package com.andy.qhb.controller.game;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.andy.qhb.base.RespVO;
import com.andy.qhb.controller.GameController;
import com.andy.qhb.dao.DaoUtils;
import com.andy.qhb.game.GameUser;
import com.andy.qhb.game.GlobalHttp;
import com.andy.qhb.utils.JsonUtils;

@Controller
@RequestMapping(value="game/api")
public class Api112Controller extends GameController{
	
	/**
	 * 移除好友
	 * @param session
	 * @param data
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="112")
	public RespVO action(HttpSession session,String data) throws Exception{
		GameUser user = getUser(session);
		Map<String, Object> reqData = JsonUtils.json2Map(data);
		Long tarId = MapUtils.getLong(reqData, "uid");
		
		user.getFriends().remove(tarId);
		DaoUtils.update(user.getFriends());
		
		GameUser tarUsr = GlobalHttp.getUser(tarId);
		if(tarUsr != null){
			tarUsr.getFriends().remove(user.getId());
			DaoUtils.update(tarUsr.getFriends());
			
//			SendUtil.send112(user,tarUsr.getId());
		}
		
		return RespVO.createSuccessJsonResonse(tarId);
	}
	
	
}